package com.jzo2o.orders.manager.Handler.OrdersHandler;

import com.jzo2o.orders.base.model.domain.Orders;
import com.jzo2o.orders.manager.model.dto.request.PlaceOrderReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 订单计算优惠处理Handler
 */
@Slf4j
@Component
@Order(30)  // 第三个执行
public class OrderCalculateHandlerNew extends OrdersHandlerNew {
    
    @Override
    public void process(Orders order, PlaceOrderReqDTO reqDTO) {
        log.info("订单计算优惠处理Handler");
        // 计算订单总金额
        order.setTotalAmount(order.getPrice().multiply(new BigDecimal(reqDTO.getPurNum())));
        // 优惠金额这里暂时为0
        order.setDiscountAmount(BigDecimal.valueOf(0));
        // 实际支付金额
        order.setRealPayAmount(order.getTotalAmount().subtract(order.getDiscountAmount()));
    }
    
    @Override
    public int getOrder() {
        return 30;
    }
}